(require 'cl)
(add-hook 'c-mode-common-hook
  '(lambda() (c-set-style "stroustrup")))
(require 'xcscope)

;; (load-library "clang-completion-mode") 
;; (require 'auto-complete-clang)
;; (setq clang-completion-suppress-error 't)
;; (setq ac-clang-flags
;;       (mapcar (lambda (item)(concat "-I" item))
;;               (split-string
;;                "
;;  /usr/include/c++/4.6
;;  /usr/include/c++/4.6/i586-suse-linux
;;  /usr/include/c++/4.6/backward
;;  /usr/lib/gcc/i586-suse-linux/4.6/include
;;  /usr/local/include
;;  /usr/lib/gcc/i586-suse-linux/4.6/include-fixed
;;  /usr/lib/gcc/i586-suse-linux/4.6/../../../../i586-suse-linux/include
;;  /usr/include
;; "
;;                )))

(add-hook 'c++-mode-hook
	  '(lambda ()
	     (define-key c++-mode-map "\C-c\C-c" 'smart-compile)
))

(add-to-list 'load-path "~/emacs/cedet/common")
(add-to-list 'load-path "~/emacs/cedet/semantic")
(require 'cedet)
(require 'semantic-ia)
(require 'semanticdb-cscope)
(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
(semantic-load-enable-guady-code-helpers)
;; (semantic-load-enable-excessive-code-helpers)
(semanticdb-enable-cscope-databases)
(semantic-load-enable-semantic-debugging-helpers)
;; system and personal header files
;; auto load gcc header
(require 'semantic-gcc)
(defconst cedet-user-include-dirs
  (list ".." "../include" "../inc" "../common" "../public"
        "../.." "../../include" "../../inc" "../../common" "../../public"
	"./"
	))
(defconst cedet-win32-include-dirs
  (list "C:/MinGW/include"
        "C:/MinGW/include/c++/3.4.5"
        "C:/MinGW/include/c++/3.4.5/mingw32"
        "C:/MinGW/include/c++/3.4.5/backward"
        "C:/MinGW/lib/gcc/mingw32/3.4.5/include"
        "C:/Program Files/Microsoft Visual Studio/VC98/MFC/Include"))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
  (when (eq system-type 'windows-nt)
    (setq include-dirs (append include-dirs cedet-win32-include-dirs)))
  (mapc (lambda (dir)
          (semantic-add-system-include dir 'c++-mode)
          (semantic-add-system-include dir 'c-mode))
        include-dirs))

(global-set-key [f8] 'semantic-ia-fast-jump)
(global-set-key [C-f8]
                (lambda ()
                  (interactive)
                  (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
                      (error "Semantic Bookmark ring is currently empty"))
                  (let* ((ring (oref semantic-mru-bookmark-ring ring))
                         (alist (semantic-mrub-ring-to-assoc-list ring))
                         (first (cdr (car alist))))
                    (if (semantic-equivalent-tag-p (oref first tag)
                                                   (semantic-current-tag))
                        (setq first (cdr (car (cdr alist)))))
                    (semantic-mrub-switch-tags first))))

(define-key c-mode-base-map (kbd "C-`") 'semantic-ia-complete-symbol)

;; (add-hook 'c-mode-common-hook '(lambda ()
;;           ;; ac-omni-completion-sources is made buffer local so
;;           ;; you need to add it to a mode hook to activate on 
;;           ;; whatever buffer you want to use it with.  This
;;           ;; example uses C mode (as you probably surmised).

;;           ;; auto-complete.el expects ac-omni-completion-sources to be
;;           ;; a list of cons cells where each cell's car is a regex
;;           ;; that describes the syntactical bits you want AutoComplete
;;           ;; to be aware of. The cdr of each cell is the source that will
;;           ;; supply the completion data.  The following tells autocomplete
;;           ;; to begin completion when you type in a . or
;; 				 (add-to-list 'ac-omni-completion-sources
;; 					      (cons "\\." '(ac-source-semantic)))
;; 				 (add-to-list 'ac-omni-completion-sources
;; 					      (cons "->" '(ac-source-semantic)))
;;           ;; ac-sources was also made buffer local in new versions of
;;           ;; autocomplete.  In my case, I want AutoComplete to use 
;;           ;; semantic and yasnippet (order matters, if reversed snippets
;;           ;; will appear before semantic tag completions).
;; 				 (setq ac-sources '(ac-source-semantic ac-source-yasnippet))
;;   ))


(add-hook 'c-mode-common-hook
          (lambda ()
	    (make-local-variable 'skeleton-pair-alist)
	    (setq skeleton-pair-alist
		  '((?{ \n > _ \n ?} >)
		  ))
            (setq skeleton-pair t)
            (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
            (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
            (local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
            (local-set-key (kbd "[") 'skeleton-pair-insert-maybe)
	    ))



(defun my-c-newline ()
  (interactive)
  (insert ";")
  (newline-and-indent)
  )
(eal-define-keys
 `(c++-mode-map c-mode-map)
 `(
   ("`" my-c-newline)
   ))
(provide 'cc-setting)